<template>
  <div class="emergency_box">
    <div class="emergency_top">
      <div class="emergency_title">故障类型分布</div>
      <div class="emergency_month">
        <div :class="this.searchDateNumber == 2? 'emergency_ThisMarch1':'emergency_March'" @click="getMarchList"><span>近三个月</span></div>
        <div :class="this.searchDateNumber == 1? 'emergency_ThisMarch1':'emergency_LastMarch'" @click="getLastMarchList"><span>上月</span></div>
        <div :class="this.searchDateNumber == 0? 'emergency_ThisMarch2':'emergency_ThisMarch'" @click="getList"><span>本月</span></div>
      </div>
    </div>
    <div v-if="tableDate&&tableDate.length>0" class="echarts_container">
      <div id="distribution" class="col-md-12  col-sm-12 col-xs-12" style="height: 100%;" />
    </div>
    <div v-else class="echarts_noData">
      <svg-icon icon-class="暂无数据" />
    </div>
  </div>
</template>

<script>
import { deviceRepairTypeDistribution } from '@/api/equipmentManage/equipmentReport/dataBoard'
export default {
  name: 'EmergencyDegreeDistribution',
  data() {
    return {
      msg: 'fafa',
      tableDate: [1],
      searchDateNumber: 0
    }
  },
  mounted() {
    this.drawLine()
    this.getList()
  },
  methods: {
    getList() {
      this.searchDateNumber = 0
      deviceRepairTypeDistribution({
        searchDateNumber: 0,
        isContinuous: 0
      }).then(res => {
        this.tableDate = res.data
        this.$nextTick(() => {
          this.drawLine()
        })
      })
    },
    getLastMarchList() {
      this.searchDateNumber = 1
      deviceRepairTypeDistribution({
        searchDateNumber: 1,
        isContinuous: 0
      }).then(res => {
        this.tableDate = res.data
        this.$nextTick(() => {
          this.drawLine()
        })
      })
    },
    getMarchList() {
      this.searchDateNumber = 2
      deviceRepairTypeDistribution({
        searchDateNumber: 2,
        isContinuous: 1
      }).then(res => {
        this.tableDate = res.data
        this.$nextTick(() => {
          this.drawLine()
        })
      })
    },
    drawLine() {
      if (!this.tableDate || this.tableDate.length == 0) {
        return
      }
      const myChart = this.$echarts.init(document.getElementById('distribution'))
      const arr = this.tableDate
      myChart.setOption({
        grid: {
          show: false,
          top: '20',
          right: '40',
          bottom: '40',
          left: '100'
        },
        color: ['#5AD1FF'],
        xAxis: {
          type: 'category',
          data: arr.map(item => item.name),
          axisTick: {
            show: false
          },
          offset: 2,
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            }
          },
          axisLine: {
            show: false
          }
        },
        yAxis: {
          type: 'value',
          // 影藏y轴刻度
          axisTick: {
            show: false
          },
          axisLine: {
            show: false
          },
          axisLabel: {
            show: true,
            color: '#999999', // 更改坐标轴文字颜色
            textStyle: {
              fontSize: 12 // 更改坐标轴文字大小
            },
            margin: 20
          }
        },
        series: [
          {
            data: arr.map(item => item.repairTypeNumber),
            silent: true,
            type: 'bar',
            barWidth: 30 // 柱图宽度
          }
        ]
      })
    }
  }
}
</script>

<style lang="less" scoped>
.emergency_box{
  width: 100%;
  height: calc(100% - 50px);
}
.emergency_top{
  display: flex;
  justify-content: space-between;
  .emergency_title{

    font-size: 24px;

    font-weight: bold;
    line-height: 34px;
    letter-spacing: -0.21px;
    color: #333333;
    padding-top: 16px;
    padding-left: 40px;
  }
  .emergency_month{
    display: flex;
    font-size: 18px;
    font-weight: normal;
    line-height: 25px;
    letter-spacing: -0.16px;
    color: #999999;
    padding-top: 22px;
    padding-right: 40px;
    cursor: pointer;
    .emergency_ThisMarch1{

      font-size: 18px;
      font-weight: normal;
      line-height: 25px;
      letter-spacing: -0.16px;
      color: #387BFC;
      padding-right: 30px;
    }
    .emergency_ThisMarch2{

      font-size: 18px;
      font-weight: normal;
      line-height: 25px;
      letter-spacing: -0.16px;
      color: #387BFC;
    }
    .emergency_March{
      padding-right: 30px;
    }
    .emergency_LastMarch{
      padding-right: 30px;
    }
  }
}
</style>

